﻿@{
    ViewBag.Title = "Home Page";
}
@using Model;
@using PagedList.Mvc;
@model PagedList.IPagedList<Contacts>

    <div> <a href="/contact/Add">添加</a></div>
<table>
   
    <thead>
        <tr>
            <th>姓名</th>
            <th>电话</th>
            <th>操作</th>
        </tr>
    </thead>
    <tbody>

        @if (Model != null && Model.Any())
        {
            foreach (var item in Model)
            {
                <tr>
                    <td>@item.UserName</td>
                    <td>@item.Tel</td>
                    <td>
                        <a href="/Contact/Detail?id=@item.Id ">查看</a>
                        <a href="javascript:void(0);" onclick="Edit()">编辑</a>
                        <a href="/contact/edit/@item.Id">编辑</a>
                        <a href="javascript:void(0);" onclick="Del('@item.Id')">删除</a>
                    </td>
                </tr>
            }
            @Html.PagedListPager(Model, page => Url.Action("Index", new { page  }))
        }
    </tbody>
</table>
<script type="text/javascript">
    function Edit()
    {
        //$.ajax({
        //    type: "POST",
        //    url: "Contact/Delete",
        //    data: "id=" + id + "",
        //    success: function (msg) {
        //        alert(msg);
        //    }
        //});
        //alert("编辑方法体");
    }
    function Del(id) {
        alert(id);
        $.ajax({
            type: "POST",
            url: "Contact/Delete",
            data: {id:id},
            success: function (msg) {
                alert("删除成功");
                window.location = location;
            }
        });
       // alert("删除方法体");
    }
</script>